import { View, Button } from '@tarojs/components';
import { useDidShow } from '@tarojs/taro';
import Taro from '@tarojs/taro';
import { StorageKey } from '@/constants/storage';
import { TabbarUtil, RouterUtil } from '@/utils';
import './index.scss';

const Test = () => {
  useDidShow(() => {
    console.log('Test page did show');
  });

  const handleSetShopId = () => {
    // 模拟设置 shopId
    Taro.setStorageSync(StorageKey.SHOP_ID, 'test-shop-123');
    Taro.setStorageSync(StorageKey.HAS_SHOP_ID, true);
    TabbarUtil.showTabbar();
    Taro.showToast({
      title: '已设置 shopId',
      icon: 'success'
    });
  };

  const handleClearShopId = () => {
    // 清除 shopId
    Taro.removeStorageSync(StorageKey.SHOP_ID);
    Taro.removeStorageSync(StorageKey.HAS_SHOP_ID);
    TabbarUtil.hideTabbar();
    Taro.showToast({
      title: '已清除 shopId',
      icon: 'success'
    });
  };

  const handleGoHome = () => {
    RouterUtil.switchTab('/pages/home/index/index');
  };

  const handleGoMy = () => {
    RouterUtil.navigateTo('/pages/my/index/index');
  };

  return (
    <View className="test-page">
      <View className="page-title">测试页面</View>
      <View className="button-group">
        <Button onClick={handleSetShopId} type="primary">
          设置 shopId (显示 tabbar)
        </Button>
        <Button onClick={handleClearShopId} type="default">
          清除 shopId (隐藏 tabbar)
        </Button>
        <Button onClick={handleGoHome} type="primary">
          跳转到主页
        </Button>
        <Button onClick={handleGoMy} type="default">
          跳转到我的页面
        </Button>
      </View>
    </View>
  );
};

export default Test;
